<template>
    <el-container>
        <el-header>
            <SearchInput placeholder="请输入医生姓名" :change="(value)=>handleYsNameChange(value)" />
            <SearchButton :click="searchDoctor" />
        </el-header>
        <el-main>
            <el-table :data="doctorData" stripe element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" v-loading.fullscreen.lock="loading">
                <el-table-column prop="mu" label="医生MU" width="180" />
                <el-table-column prop="ysName" label="医生名称" width="180" />
                <el-table-column prop="zsName" label="诊所" width="300" />
                <el-table-column prop="city" label="城市" width="200" />
                <el-table-column label="操作" width="380">
                    <template #={mu}>
                        <PlainButton text="显示案例" :click="()=>searchCase(mu)" />
                        <PlainButton text="添加案例" :click="()=>showAdd(mu)" />
                    </template>
                </el-table-column>
            </el-table>
            <el-table :data="tableData" stripe>
                <el-table-column prop="mu" label="案例MU" width="180" />
                <el-table-column prop="title" label="案例标题" width="300" />
                <el-table-column label="案例详细" min-width="380">
                    <template #="scope">
                        <el-input type="textarea" disabled v-model.trim="tableData[scope.$index].info" :autosize="{ minRows: 2, maxRows: 20}" />
                    </template>
                </el-table-column>
                <el-table-column label="封面图片" width="200">
                    <template #={imageUrl}>
                        <el-image style="width: 148px; height: 148px" fit="fill" :src="imageUrl||''" :preview-src-list="[imageUrl]">
                            <template #:error>
                                <el-tooltip effect="dark" content="还未选择封面" placement="top">
                                    <i class="el-icon-edit-outline" style="font-size: 160px" />
                                </el-tooltip>
                            </template>
                        </el-image>
                    </template>
                </el-table-column>
                <el-table-column label="是否置顶" width="80">
                    <template #={isTop}>
                        <div v-if="isTop=='1'">置顶</div>
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" width="180" />
                <el-table-column prop="adminName" label="添加人员" width="80" />
                <el-table-column label="操作" width="200">
                    <template #={mu}>
                        <PlainButton text="编辑" :click="()=>showUpdate(mu)" />
                        <PlainButton text="删除" :click="()=>doDelete(mu)" />
                    </template>
                </el-table-column>
            </el-table>
            <SearchPagination :currentPage="currentPage" :total="total" :limit="limit" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" />
        </el-main>
    </el-container>
</template>

<script>
import Data from '@/chaos/functions/common/Data';
import Show from '@/chaos/functions/common/Show';
import { page, remove } from '@/chaos/functions/mixin/crud';
import { pushupdate } from '@/chaos/functions/mixin/pushcrud';

export default {
    name: 'cases',
    mixins: [page, remove, pushupdate],
    data() {
        return {
            domain: 'iya_case',
            ysName: '',
            updatePath: 'updateCase',
            doctorData: []
        };
    },
    activated() {
        if (this.data.doctorMu) this.search();
    },
    methods: {
        handleYsNameChange(ysName) {
            this.ysName = ysName;
            this.searchDoctor();
        },
        async searchDoctor() {
            this.doctorData = [];
            this.tableData = [];
            if (!this.ysName) {
                Show.info('请输入医生姓名');
                return;
            }
            this.doctorData = await Data.list('iya_doctor', {
                ysName: this.ysName
            });
        },
        searchCase(doctorMu) {
            this.data.doctorMu = doctorMu;
            this.search();
        },
        showAdd(doctorMu) {
            this.$router.push({
                name: 'addCase',
                params: { doctorMu }
            });
        }
    }
};
</script>
<style scoped>
</style>
